<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*,java.text.DecimalFormat"%>
<%@ taglib uri="/WEB-INF/commontags.tld" prefix="common" %><%--페이징처리tag--%>
<jsp:include page="common/header.jsp"></jsp:include>
<%
	UserSession usersession = (UserSession)session.getAttribute("user");
	String ent_id 			= (String)session.getAttribute("ent_id");
	
	String connGroup 	= "";
	String user_id 		= "";
	if(usersession!=null){
		connGroup 	= CmmUtil.nvl(usersession.getConnGroup(),"0");
		user_id 	= CmmUtil.nvl(usersession.getUser_id(),"");
	}
	String keyword_gb 	= CmmUtil.nvl(request.getParameter("search_gb"),"");
	String keyword 		= CmmUtil.nvl(request.getParameter("search_word"),"");
	String line_number	= CmmUtil.nvl(request.getParameter("line_number"),"10");
	
	System.out.println("keyword  " + keyword);
	
	String present_Year = String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR));
	//GregorianCalendar에서 1월 return 값이 0이므로 Month에는  1을 더해주어야 함
	String present_Month = String.valueOf(GregorianCalendar.getInstance().get(Calendar.MONTH)+1); 
	String present_Date = String.valueOf(GregorianCalendar.getInstance().get(Calendar.DATE));
	
	if(present_Month.length() == 1){
		present_Month = "0" + present_Month; //01월,02월 ..... 09월
	}
	
	GregorianCalendar g = new GregorianCalendar();
	g.add(Calendar.MONTH, 0);
	
	String befor_Month = String.valueOf(g.get(Calendar.MONTH));
	
	if(befor_Month.length() == 1){
		befor_Month = "0" + befor_Month; //01월,02월 ..... 09월
	}
	
	if(present_Date.length() == 1){
		present_Date = "0" + present_Date; //01일,02일 ..... 09일
	}
	
	//start_dt,close_dt,selected_year,selected_month 의 값에 받아오는 인자가 없을 경우 default로 현재 시간을 Setting
	String start_dt 		= CmmUtil.nvl(request.getParameter("start_dt"),present_Year + befor_Month + present_Date);
	String close_dt 		= CmmUtil.nvl(request.getParameter("close_dt"),present_Year + present_Month + present_Date);

	//페이징 처리 Start
 	//페이지 표시정보 받기 혹은 검색입력창
 	String curr_page = request.getParameter("curr_page");
 	if (curr_page == null || curr_page.equals(""))
 		curr_page = "1";
 	String one_page = request.getParameter("line_number");
 	if (one_page == null || one_page.equals(""))
 		one_page = "10";
 	String one_group = request.getParameter("one_group");
 	if (one_group == null || one_group.equals(""))
 		one_group = "10";
 	
 	String total_count = CmmUtil.nvl(request.getParameter("total_count"),"0");
 	
 	//페이징 처리 End
 	
 	ArrayList al1 = new ArrayList();
 	
 	HashMap al1_map = null;
 	
 	
	HashMap map = new HashMap();

	ArrayList list = new ArrayList();
	CommonDaoService commonservice = new CommonDaoService("Com0102lp02Dao");
	map.put("connGroup",connGroup);
	map.put("user_id",user_id);
	map.put("ent_id",ent_id);
	map.put("keyword",keyword);
	map.put("search_combo",keyword_gb);
	map.put("start_dt",start_dt);
	map.put("close_dt",close_dt);
	map.put("page_row",line_number);
	map.put("total_row",total_count);
	map.put("page_no",curr_page);
	
	list = (ArrayList)commonservice.commonDaoMethod(map);
	
	//System.out.println(list);
	
	int fin_y_cnt=0;
	int fin_n_cnt=0;
	
	if(list != null){
		if(list.size() > 0){
			al1 = (ArrayList)list.get(0);
			
			
			if(al1 != null && al1.size() > 0){
				total_count = (String)((HashMap)al1.get(0)).get("total_row");
				
				if(((HashMap)al1.get(0)).get("fin_y_cnt").toString() != null){
					fin_y_cnt = Integer.parseInt(((HashMap)al1.get(0)).get("fin_y_cnt").toString());
					fin_n_cnt = Integer.parseInt(((HashMap)al1.get(0)).get("fin_n_cnt").toString());
				}
			}
			System.out.println("total_count " + total_count);
			
			
			
		}
	}
	
	/*수료 미수료 수와 수료율*/
	double cer_persent = 0;
	if(Integer.parseInt(total_count) > 0){
		cer_persent = fin_y_cnt / (double)Integer.parseInt(total_count) ;
		cer_persent= cer_persent*100;
	}
	 DecimalFormat df = new DecimalFormat("###.##");
	 
	
	//진도 팝업으로 넘어갈 hidden value
	String poi_kisu_std_no	="";
	String poi_nm			="";
	String login_nm			="";
	
	//SMS
	String id 				="";
	String uni_id			="";
	String cell_phone_no 	="";
	
	String rownum			="";
	
%>
<script>
//검색
function search(){
	var frm = document.mainfrm;
	frm.curr_page.value ="1";
	frm.total_count.value = "0";
	frm.action = "/jsp/com0102l_p02.jsp";
	frm.target="_self";
	frm.submit();
}

// 페이지 번호를 눌렸을때.
function go_page(page){
	var frm = document.mainfrm;
	frm.curr_page.value = page ;			
	frm.total_count.value = "<%=total_count%>";
	frm.search_word.value = "<%=keyword%>";
	frm.action = "/jsp/com0102l_p02.jsp";
	frm.target="_self";
	frm.submit();
}

//진도 팝업
function jindo_Pop(poi_kisu_std_no,poi_nm,login_nm){
	var frm = document.mainfrm;
	open("","viewPop","width=640,height=400,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes ");
	frm.poi_kisu_std_no.value = poi_kisu_std_no;
	frm.poi_nm.value = poi_nm;
	frm.poi_login_nm.value = login_nm;
	frm.action = "/jsp/pop/com0102l_p02_pop01.jsp";
	frm.target="_self";
	frm.target = "viewPop";
	frm.method = "post";
	frm.submit();
}

function final_totPop(poi_kisu_std_no){
	var frm = document.mainfrm;
	open("","viewPop","width=640,height=400,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes ");
	frm.poi_kisu_std_no.value = poi_kisu_std_no;
	frm.action = "/jsp/pop/com0102l_p02_pop02.jsp";
	frm.target="_self";
	frm.target = "viewPop";
	frm.method = "post";
	frm.submit();
}

//SMS발송 팝업
function smsPop(){
	var frm = document.mainfrm;
	var checkboxObject = document.getElementsByName("checkbox");
	var cLength =  checkboxObject.length;
	var submitOk = "";
	
	for(var i=0; i< cLength; i++){
		if(checkboxObject[i].checked == true){
			submitOk ="true";
		} 		
	}
	if(submitOk == ""){
		alert("SMS를 발송할 회원을 선택해주세요");
		return;
	}
	
	open("","viewPop","width=530,height=400,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes ");
	frm.action = "/jsp/pop/smsPop.jsp";
	frm.target = "viewPop";
	frm.method = "post";
	frm.submit();
}

//엑셀다운로드
function excel_down(){
	var frm = document.mainfrm;
	frm.action = "/jsp/com0102l_p02_excel.jsp";
	frm.target="_blank";
	frm.method = "post";
	frm.submit();	
}

//전체 승인 선택
function all_check(){
	var frm = document.mainfrm;
	var cnt =document.getElementsByName("checkbox").length;
	for(var i=0; i<cnt; i++){
		document.getElementsByName("checkbox")[i].checked=true;
	}
}

//전체 취소 선택
function all_disable_check(){
	var frm = document.mainfrm;
	var cnt =document.getElementsByName("checkbox").length;
	for(var i=0; i<cnt; i++){
		document.getElementsByName("checkbox")[i].checked=false;
	}
}

/*수료처리*/
function end_Submit(gu) {
	var chk_cnt = 0;
	var cnt =document.getElementsByName("checkbox").length;
	for(var i=0; i<cnt; i++){
		if(document.getElementsByName("checkbox")[i].checked==true){
			 chk_cnt++;
			 document.getElementsByName("end_gubun")[i].value = gu;			 
		}
	}

	if(chk_cnt == 0){
		if(gu == 'end') {
			alert("수료처리할 대상자를 선택해 주세요.");
		}else{
			alert("미수료처리할 대상자를 선택해 주세요.");
		}
		return;
	}

	var frm = document.mainfrm;
	frm.action = "/jsp/com0102l_p02_update.jsp";
	frm.target ="hide_src";
	frm.submit();
}

</script>
<body>
<table width="992" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td>
    <!--top -->
    <jsp:include page="common/top_menu.jsp"></jsp:include>
    <!-- //top -->
    <!-- contents area -->
<form name="mainfrm" method="post">
<input type="hidden" name="curr_page" value="<%=curr_page%>">
<input type="hidden" name="total_count" value="<%=total_count%>">
<input type="hidden" name="ent_id" value="<%=ent_id%>">

	<!-- 진도(popup) 로 넘길 인자 -->
<input type="hidden" name="poi_kisu_std_no" value="">
<input type="hidden" name="poi_nm" value="">
<input type="hidden" name="poi_login_nm" value="">
	<!-- 진도(popup) 로 넘길 인자 -->

  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="180" valign="top">
    	<jsp:include page="left/com0101l_p05.jsp"></jsp:include>
    </td>
    <td width="21" valign="top">&nbsp;</td>
    <td valign="top">
    	 <table width="790px"  border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="font-size:14px; color:#3b70a2; font-weight:bold; border-bottom:2px solid #c8c8c8; padding:0 0 5px 0;" align="left"><img src="/images/sub_icon1.jpg"  alt="" border="0">&nbsp;학습관리 - 학습현황</td>
             </tr>
        </table>
        <table width="790px"  border="0" cellpadding="0" cellspacing="0">
         <tr>
        	<td width="100%">
            	<iframe name='stu_state' src="/jsp/ifm/stu_state.jsp?start_dt=<%=start_dt %>&close_dt=<%=close_dt %>"  width='100%' height='100' SCROLLING='AUTO' frameborder='0'></iframe>     
              </td>
         </tr>
		 <tr><td>
				<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="main_table4">
                  <tr>                    
                    <td class="table_th">수료</td>
                    <td class="table_th">미수료</td>
                    <td class="table_th">수료율</td>                    
                  </tr>
                  <tr>                    
                    <td><%=fin_y_cnt %></td>
                    <td><%=fin_n_cnt %></td>
                    <td><%=df.format(cer_persent) %>%</td>                    
                  </tr>
                </table> 	           
			</td>
		</tr>
        </table>
		<table width="790px" border="0" cellpadding="0" cellspacing="0" style="margin:20px 0 0 0">
			<tr>
				<td align="left">
					<jsp:include page="common/selectbox_list.jsp"></jsp:include> 
				</td>
				<td align="right">검색일자
					<input type="text" name="start_dt" id="start_dt" class="textbox" value="<%=start_dt %>"/>
					<script language=javascript>
					var basicCal = new calendar("FIELD:document.mainfrm.start_dt;FORMAT:2;DELIMITER:;");
    				basicCal.writeCalendar();
    				</script>
					~
					<input type="text" name="close_dt" id="close_dt" class="textbox" value="<%=close_dt %>"/>
					<script language=javascript>
					var basicCal = new calendar("FIELD:document.mainfrm.close_dt;FORMAT:2;DELIMITER:;");
    				basicCal.writeCalendar();
    				</script>
					&nbsp;&nbsp;
					<select name="search_gb">
						<option value="" <%if(keyword_gb.equals("")){%>selected<%}%>>검색조건</option>
                 		<option value="1" <%if(keyword_gb.equals("1")){%>selected<%}%>>성명</option>
                 		<option value="2" <%if(keyword_gb.equals("2")){%>selected<%}%>>과정명</option>
               		</select>
					<input type="text" name="search_word" value="<%=keyword %>" class="textbox" required="required" hname="검색어" />
					<a href="javascript:search()"><img src="/images/bt_search2.gif" align=absmiddle /></a>
				</td> 
				
			</tr>
		</table>
		
         <table width="790px" border="0" cellspacing="0" class="bbs_property" summary="" style="font-size:11px; margin:13px 0 20px 0;">
            <caption></caption>
            <thead>
             <tr>
              <th>No</th>
              <th>과정</th>
              <th>성명</th>
              <th>기수</th>
              <th>진도</th>
              <th>과제</th>
              <th>최종</th>
              <th>총점</th>
              <th>수료대상</th>
			  <th>수료</th>
              <th>선택</th>
             </tr>
            </thead>
            <tbody>
            <%for(int i=0; i<al1.size(); i++){
            	al1_map = (HashMap)al1.get(i);
            	//System.out.println(al1_map);
            	poi_kisu_std_no = (String)al1_map.get("poi_kisu_std_no");
            	poi_nm			= (String)al1_map.get("poi_nm");
            	login_nm		= (String)al1_map.get("login_nm");
            	
            	cell_phone_no 	= CmmUtil.nvl((String)al1_map.get("cell_phone_no"),"--");
            	id 				= Crypto.DecodeBySType((String)al1_map.get("login_id"));
            	uni_id			= CmmUtil.nvl((String)al1_map.get("uni_id") ,"");
            	
            	rownum			= CmmUtil.nvl((String)al1_map.get("rownum") ,"");
            %>
            
	<!-- SMS발송(popup) 으로 넘길 인자 -->
<input type="hidden" name="cell_phone_no" value="<%=cell_phone_no%>">
<input type="hidden" name="login_nm" value="<%=login_nm %>">
<input type="hidden" name="uni_id2" value="<%=uni_id %>">
<input type="hidden" name="user_id" value="<%=id %>">
	<!-- //SMS발송(popup) 으로 넘길 인자 -->

	
	<!-- 수료처리 으로 넘길 인자 -->
<input type="hidden" name="su_poi_kisu_std_no" value="<%=poi_kisu_std_no%>">
<input type="hidden" name="su_user_id" value="<%=user_id %>">
<input type="hidden" name="end_gubun" value="">
	<!-- //수료처리 으로 넘길 인자 -->
             <tr>
              <td scope="row" class="ranking"><%=rownum %></td>
              <td align="left"><%=poi_nm%></td>
              <td><%=login_nm%></td>
              <td><%=al1_map.get("kisu_info") %></td>
              <td style="background:#ebf7d4;"><a href="javascript:jindo_Pop('<%=poi_kisu_std_no %>','<%=poi_nm %>','<%=login_nm %>')"><%=al1_map.get("final_prog_rate") %></a></td>
              <td><%=al1_map.get("rpt_point") %></td>
<%if(al1_map.get("final_eval_point").equals("미응시")){ %>
			  <td style="background:#ebf7d4;"><%=al1_map.get("final_eval_point") %></td>
<%}else{ %>
              <td style="background:#ebf7d4;"><a href="javascript:final_totPop('<%=poi_kisu_std_no %>')"><%=al1_map.get("final_eval_point") %></a></td>
<%} %>              
			  <td><%=al1_map.get("tot_point") %></td>
              <td><%=al1_map.get("fin_whether") %></td>
			  <td><%=al1_map.get("fin_status") %></td>
              <td><input type="checkbox" name = "checkbox" id="checkbox" onclick="" value="<%=i%>"></td>
             </tr>
             <%}%>
            </tbody>
            </table>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
             <tr>
  
                <td align="right">
					<!-- 페이징 -->
					<common:pagelistnew currPage="<%=curr_page%>" total="<%=total_count%>" onePage="<%=one_page%>" oneGroup="<%=one_group%>"/>
					<!-- //페이징 -->
           	  		<table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                          <td width="84px" align="left">
                            <table border="0" cellpadding="0" cellspacing="0" style="margin:0 0 10px 0;">
                                <tr>
                                  <td><a href="javascript:smsPop()"><img src="/images/btn_sms_btn.gif" align="absmiddle" /></a></td>
                                   <td align="left" style="padding:0 0 0 3px;"><a href="javascript:excel_down()"><img src="/images/btn_save_excel2.gif" align="absmiddle" /></a></td>
                              </tr>
                            </table>
                          </td>
						  <td align="right">
                        	<table border="0" cellpadding="0" cellspacing="0" >
                                <tr>
                                  <td><input name="button" type="button" class="btn_gray_blue1"  value="전체선택" onClick="javascript:all_check()" /></td>
                                  <td align="left" style="padding:0 0 0 3px;"><input name="button3" type="button" class="btn_gray_blue1"  value="전체취소선택" onclick="javascript:all_disable_check()"/></td>
                                  <!-- 
                                  <td align="left" style="padding:0 0 0 3px;"><input name="button3" type="button" class="btn_gray_blue2"  value="수료" onclick="end_Submit('end')"/></td>
								  <td align="left" style="padding:0 0 0 3px;"><input name="button3" type="button" class="btn_gray_blue2"  value="미수료" onclick="end_Submit('re')"/></td>
                                   -->
                                </tr>
                            </table>
                          </td>
                        </tr>
                    </table> 
               </td>
             </tr>
           </table>
    </td>
    </tr>
	</table>
</form>
   
	<jsp:include page="common/footer.jsp"></jsp:include>
	</td>
  </tr>
</table>
<iframe name='hide_src'  width='0' height='0' SCROLLING='AUTO' frameborder='0'></iframe>
</body>
</html>
